from datetime import datetime
from pydantic import BaseModel, Field, validator
from typing import Optional
import re


# Base Schema
class MatchBase(BaseModel):
    league: str = Field(..., max_length=50)
    home: str = Field(..., max_length=50)
    away: str = Field(..., max_length=100)
    start_time: int
    prediction: str = Field(..., max_length=50)
    random: str = Field(..., max_length=4)
    hash: str = Field(..., max_length=100)
#    score: Optional[str] = Field(None, max_length=50)
    score:  Optional[str] = Field(None, max_length=50)
    performance:  Optional[str] = Field(None, max_length=50)
    fb_id: int
    weight: float


# Create Schema (需包含所有必填字段)
class MatchCreate(MatchBase):
    pass


# Update Schema (所有字段可选)
class MatchUpdate(BaseModel):
    league: Optional[str] = Field(None, max_length=50)
    home: Optional[str] = Field(None, max_length=50)
    away: Optional[str] = Field(None, max_length=100)
    start_time: Optional[int] = None
    prediction: Optional[str] = Field(None, max_length=50)
    random: Optional[str] = Field(None, max_length=4)
    hash: Optional[str] = Field(None, max_length=100)
    score: Optional[str] = Field(None, max_length=50)
    performance: Optional[str] = Field(None, max_length=50)
    fb_id: Optional[int] = Field(None, ge=0, le=10**50 - 1)
    weight: Optional[float] = Field(None, ge=0, le=10 ** 50 - 1)

# Response Schema (包含所有字段)
class Match(MatchBase):
    id: int

    class Config:
        from_attributes = True